﻿'This file is part of WSUS Helper <http://wsushelper.codeplex.com/>.

'WSUS Helper is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 2 of the License, or
'(at your option) any later version.

'WSUS Helper is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with WSUS Helper.  If not, see <http://www.gnu.org/licenses/>.

Public Class Log


    Private Sub Log_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        tLog.Text = Main.sbLog.ToString
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        If sfToTXT.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                Dim oTXT As New IO.StreamWriter(sfToTXT.FileName)

                Try
                    oTXT.Write(Main.sbLog.ToString)
                    oTXT.Close()
                Catch ex As Exception
                    'Lazy error message box
                    Dim sError As String = "Problem while saving to file " & sfToTXT.FileName & ": " & ex.Message
                    MessageBox.Show(sError, "Problem while saving", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Main.LogThis(sError)
                    tLog.AppendText(sError & vbCrLf)
                Finally
                    oTXT.Close()
                End Try

            Catch ex As Exception
                'Lazy error message box
                Dim sError As String = "Unable to save to file " & sfToTXT.FileName & ": " & ex.Message
                MessageBox.Show(sError, "Unable to save", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Main.LogThis(sError)
                tLog.AppendText(sError & vbCrLf)
            End Try
        End If

    End Sub
End Class